/** 
 * https://leetcode.cn/submissions/detail/373390812/
 * 03. 无重复字符的最长子串
 * medium, 黄驰 2022.10.16
 * 滑动窗口
 */

#include <bits/stdc++.h>
using namespace std;

class Solution {
int a[200] = {0};
public:
    int lengthOfLongestSubstring(string s) {
        int i = 0, j = 0, ma = 0;
        for (char &c: s) {
            while (a[c]) a[s[i++]]--;
            a[c]++;
            ma = max(ma, j++ - i + 1);
        }
        return ma;
    }
};

int main() {
    Solution sln;
    string s = "abcabcbb";
    int ans = sln.lengthOfLongestSubstring(s);
    cout << ans << endl;
    return 0;
}